<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试接口跨域问题</title>
    <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <button id="get">GET</button>
    <button id="post">POST</button>
</body>
<script>
    $(function() {
        $('#get').click(function() {
                $.ajax({
                    type: 'GET',
                    url: 'http://127.0.0.1/api/get',
                    data: {
                        name: 'zs',
                        age: 20
                    },
                    success: function(res) {
                        console.log(res);
                    }
                })
            }),
            $('#post').click(function() {
                $.ajax({
                    type: 'POST',
                    url: 'http://127.0.0.1/api/post',
                    data: {
                        name: 'zs',
                        age: 20,
                        gender: '男'
                    },
                    success: function(res) {
                        console.log(res);
                    }
                })
            })
    })
</script>

</html>